package leetcodecompetition.D365;

/**
 * @Author: Siantar
 * @Date: 2023-10-01-10:32
 * @Description: 1.0
 */
public class T100088 {
    public long maximumTripletValue(int[] nums) {
        int n=nums.length;
        int []rightMax=new int[n];
        rightMax[n-1]=nums[n-1];
        for (int i = n-2; i >=0; i--) {
            rightMax[i]=Math.max(rightMax[i+1],nums[i]);
        }
        int leftMax=nums[0];
        long res=0;
        for (int i = 1; i < n-1; i++) {
            res=Math.max(res,(long) (leftMax-nums[i])*rightMax[i+1]);
            leftMax=Math.max(leftMax,nums[i]);
        }
        return res;
    }
}
